- MAKING THE MOST OF YOUR
eR Tey &
te Fete ee
Ph afr re ness
\
APPLICATION : Kscp Next Week
STEPPING OUT Our series on robotics ee
continues with a look at the mechanics and | | we compare lap-helds from
control of robot movement © | | iret Me ond Tandy =
: : different versions of the same
- 7 / _ | Basic computer.
HARDWARE | @ Our robotics series :
, = investigates and simulates th
CUDDLY TOY The Koala-pad is a dedicated a
graphics tablet that greatly enhances graphics _ © We introduce you to the
on the Commodore 64 7 dynaturtle, in a LOGO-based
guided tour of vector algebra.
SUM OF THE PARTS We begin a new series
on integrated software — one of the latest —
‘Innovations of computer design — by looking
at the three governing principles
ORIGIN OF THE SPECIES Pacman versions
are available for most of the popular home
micros, but how well do they compare to the
original? We review the game for the Vic-20
and Spectrum
DIVIDE AND RULE Our Loco series
continues on the theme of recursion. In this
instalment we design a number of complex
patterns and shapes
FLOPPY DISK TO FORMAT A weekly _
glossary of computing terms
PROGRAMMING PROJECTS
ON YOUR BIKE We write a fast-action game
in BASIC for two players on the Spectrum that 637
demands skill and concentration
Editor Vike Wesley. Art Director David Whelan: Technical Editor Brian Morris: Production Editor Catherine
Cardwell, Art Editor Claudia Zeff; Chief Sub Editor Robert Pickering: Designer Julian Dorr Art Assistant Liz
Dixon, Editorial Assistant Stephen Malone; Sub Editor Steve Wann: Researcher Vielanie Davis: Staff Writer
steve Colwill, Contributors Geoff Bains, Harvey Mellor, Mike Curtis, Steve Colwill, Chris Naylor, Max Phillips, Matt
Nicolson, Steve Malone; Software Consultants Pilot Software City, Group Art Director Perry Neville. Managing
Director Stephen England, Published by Orbis Publishing Ltd: Editorial Director Brian Innes: Project Development
| Peter Brookesmith, Executive Editors Chris Cooper, Maurice Geller, Production Controller Peter Taylor
Medhurst, Gireulation Director David Breed, Marketing Director Michael Joyce: Designed and produced by
Bunch Partworks Ltd; Editorial Office 14 Rathbone Place, London WIP 1DE. © APSIF Copenhagen 1984; © Orhis
eet Lid 1984: Typeset by Universe; Reproduction by Mullis Morgan Ltd; Printed in Great Britain by Artisan
Press Ltd, Leicester
HOME COMPUTER ADVANCED COURSE - Price UK 80p IR £1.00 AUS $1.95 NZ S2 25 SA R195 SINGAPORE $4 50
USA and CANADA $1.95 :
How to obtain your copies of HOME COMPUTER ADVANCED COURSE - Copies are obtainable by placing a regular
order at your newsagent, or by taking out a subscription. Subscription rates: for six months (26 issues) £23 80:
for one year (92 issues) £47.60. Send your order and remittance to Punch Subscription Services, Watling Street, |
Bletchley, Milton Keynes, Bucks MK2 2BW, being sure to state the number of the first issue required. :
Back Numbers UK and Eire — Back numbers are obtainable from your newsagent or from HOME COMPUTER
ADVANCED COURSE. Back numbers, Orbis Publishing Limited, 20/22 Bedfordbury, LONDON WC2N 4B7 at cover
price. AUSTRALIA: Back numbers are obtainable from HOME COMPUTER ADVANCED COURSE, Back numbers.
Gordon & Gotch (Aus) Ltd, 114 William Street, PO Box 76/7G Melbourne, Vic 3001, SOUTH AFRICA, NEW
ZEALAND, EUROPE & MALTA: Back numbers are available at cover price from your newsagent. In case of difficulty
write to the address in your country given for binders. South African readers should add sales tax.
How to obtain binders for HOME COMPUTER ADVANCED COURSE — UK and Eire: Please send £3.95 per binder if you
do not wish to take advantage of our special offer detailed in Issues 5, 6 and 7, EUROPE: Write with remittance of
£9.00 per binder (incl. p&p) payable to Orbis Publishing Limited, 20/22 Bedfordbury, LONDON WC2N 4BT
MALIA: Binders are obtainable through your local newsagent price £3.95. In case of difficulty write to HOME
COMPUTER ADVANCED COURSE BINDERS, Miller (Malta) Ltd, M.A. Vassalli Street, Valletta, Malta. AUSTRALIA.
For details of how to obtain your binders see inserts in early issues or write to HOME COMPUTER ADVANCED
COURSE BINDERS, First Post Pty Ltd, 23 Chandos Street, St. Leonards, NSW 2065. The binders supplied are
those illustrated in the magazine. NEW ZEALAND: Binders are available through your local newsagent or from
HOME COMPUTER ADVANCED COURSE BINDERS, Gordon & Gotch (NZ) Ltd, PO Box 1595, Wellington. SOUTH
AFRICA: Binders are available through any branch of Central Newsagency. In case of difficulty write to HOME
COMPUTER ADVANCED COURSE BINDERS, Intermag, PO Box 5/394, Springfield 2137.
Note - Binders and back numbers are obtainable subject to availability of stocks. Whilst every attempt is made to
keep the price of the issues and binders constant, the publishers reserve the right to increase the stated prices at
MACHINE CODE
JUMP LEADS Having mastered direct
addressing, our 6809 code course progresses to 63/
indirect addressing | : |
TRAFFIC CONTROL Webring ourtwin-
motor vehicle under the control of a joystick 634
using the two devices built in previous weeks
REFERENCE CARD A valuable reference INSIDE
, in | BACK any time when circumstances dictate. Binders depicted in this publication are those produced for the UK market
card that comp lements the machine code COVE R only and may not necessarily be identical to binders produced for sale outside the UK. Binders and issues may be
course Subject to import duty and/or local taxes, which are not included in the above prices unless stated.
COVER PHOTOGRAPHY BY MARCUS WILSON-SMITH
The Straight
And Narrow |
Walking on two legs is an
enormously difficult task for
robots. Walking begins with a
shift in the centre of gravityso —
that the body topples forwards;
the trailing leg is raised while the
shoulder turns and the arms
swing, bringing the body’s weight
forward and sideways onto the
leading foot; the body continues
to topple as the lifted leg swings
through and onto the heel.
Balance is maintained throughout g
by co-ordinating the movements
of the large body masses, and by
pushing the body sideways and
forwards with the toes
ee
In the first part of our series on robotics we
looked at how robots have developed from
science fiction fantasy to the ‘metal collar’
workers of today’s production lines. Now we
discuss the three principal methods of robot
movement and the most efficient n means of
controlling it.
ee ee Le
Long before a child learns to walk it will be capable
of picking objects up and will demonstrate
intelligence in numerous other ways, but walking
‘is a skill that takes a long time to develop and
which involves considerable practice before it
becomes automatic.
Robots can be made to ‘walk’, but the
techniques involved are very different from the
methods used by people. ‘The robot may have legs,
which it can swing backwards and forwards in an
approximation of ahuman walk, but each of these
legs is equipped with a foot that has wheels on its
base. These wheels are fitted with ratchets to
inhibit backward movement. So a robot of this
type follows a set sequence of actions as it ‘walks’.
The disadvantage of this method it that it is
"difficult to develop a way of steering. the robot; it
will tend to move in a forward direction only and
its movements will be imprecise.
A much better solution would be to make
HIP JOINT
KNEE JOINT
ARMOURED KNEECAPS —
~ HINGED ANGLE JOINT —
Hibibese SURFACES ‘ WRAP-AROUND HEEL
‘STEVE CROSS.
robots walk by lifting first one leg and then the
other, as humans do, instead of simply swinging — Saale
each limb through a limited arc. The major
problem with this approach is that the robot must
be able to balance on one leg as it walks. Various -
solutions have been tried: thesé include tilting the
robot’s body sideways and even moving the entire
torso sideways on a rail so that the robot's centre of
gravity is kept directly above the leg that is bearing
its weight. If such a system were developed, robots
could walk in an efficient manner. In theory,
a walking robot could be designed to climb stairs .
and bring its owner a morning cup of tea. But in
practice, although a robot that can climb stairs is
quite feasible, a robot that ‘knew’ when it had
reached the top of the stairs would be harder to
develop because of the extra apparatus needed to
detect the top step.
An alternative approach has been to mount
robots on tracks. The advantage of this system is
that it allows the robot to travel over rough ground.
The British Army uses tracked robots for carrying
out hazardous bomb-disposal duties; these |
machines can manoeuvre through debris and can
cover reasonably rough ground.
Tracks are robust and are easily driven, but they
have two main drawbacks. The first is that, as most
robots are fairly small, so the size of the tracks is
small and hence large obstacles cannot be
THE HOME COMPUTER ADVANCED COURSE 621
APPLICATION / ROBOTICS
\\oooO0]f
*8\ 9 0 010 /F
negotiated. A full-size battle tank can climb over
almost any obstacle with ease — but this is only
because tanks are so large, heavy and powerful. If
a tank tries to climb over an object so large that the
tank’s centre of gravity is moved outside the area
of its tracks it will fall over. This does in fact
happen occasionally when the ground is very
rough. The same thing will happen to your tracked
robot if it tries to climb over surfaces that are too
steep.
The second disadvantage is that tracks cannot
be controlled precisely. Steering is carried out by
halting one track so that the other track continues
running; the robot (or tank) thus moves through
an arc. When this happens, the stationary track
may easily slip slightly and the final position may
not be what was expected. A battle tank that is
driven by a person can readily correct any error of
this kind but, for a robot, the necessary course
corrections are considerably more complicated.
For robot control, it is obviously desirable to
have a set of instructions that will always cause the
robot to move to exactly the right place, facing in
an exactly predictable direction. For these reasons,
the most common form of robot movement uses
wheels. Wheels have several obvious advantages,
being simple, efficient and capable of producing a
much smoother movement than legs could ever
manage. |
Once it has been accepted that the robot should
use wheels, the only problem is exact control of
the movement. Consider, for instance, a
clockwork toy motor car. This runs on wheels but
it is not a robot, as it has no means of ‘knowing’ its _
position at any given time. What is needed is a co-
ordinate system that can be used to determine an
object’s position on a surface — the most common
system for this purpose uses Cartesian co-
ordinates. With this system it is possible to locate a
robot’s precise position and to specify the
Roll Those
Robots!
622 THE HOME COMPUTER ADVANCED COURSE
movements needed to move it to another defined
location. All that is then needed is a device to
ensure that the robot can move precisely within
this frame of reference.
Although hydraulic or pneumatic power is
occasionally used, the most common method of
moving robots is via an electric motor. As we have
seen in our Workshop series (pages 585 and 612),
a simple electric motor can provide movement
and a modest amount of control over direction.
This is not suitable for precise control — a simple
electric motor always turns through at least 180
degrees before coming to rest, and inertia will
often cause it to rotate a little more than that.
So, for robot control, the stepper motor is
normally used. This is a motor that contains a large
number of coils and, although designs may vary
widely, the general principle of the stepper motor
allows very small, exact amounts of rotation to be
specified, with little overshoot (rotating more than
it should) or undershoot (rotating too little).
Robots that use stepper motors are widely
available. Such robots often have a pen attached,
allowing them to draw a line on the surface they
are travelling over. These pen-wielding robots are
called ‘turtles’, and the designs they produce are
known as ‘turtle graphics’. These are capable of —
precise movement — their accuracy may be
_ judged by instructing them to draw a closed shape,
such as a rectangle or a star, and checking to see
whether or not the line drawn meets itself at the
Starting point.
_ Stepper motors and Cartesian co-ordinates can
therefore give us a relatively precise method of
controlling a robot’s movement. However, if the
robot is to do more than simply roll around in a
given area, bumping into obstacles, it will need to
be able to respond quickly and accurately to
external conditions. We will consider oe further
in the next instalment.
Stepping
Measure
AXIS OF ROTATION oan
In the simplest electric motor, a
flow of current in the rotor coil
Creates a magnetic flux :
opposed to that of the stator
magnet's field; this opposition
of forces causes the rotor to
| turnin the field
The stepper motor has
many (sometimes hundreds) of
coils. Switching current from
one coil to another causes the
| whole to rotate in precisely
controllable increments of arc
KEVIN JONES
Robots must move, and not just
on smooth laboratory floors. We
show a few of the possible
_mechanisms.
racked eet give arip at the
COSI 07 siecrabilily, bul allow a
shiutiling gait without lea-liit, thus
lessening balance problems.
Tracked robot vehicles are
_ Commonplace — with bomb
Squads aiid planetary exploration
teams, ior example.
The tr-axie formal is the only
wheel adaptation that allows the
robottocimp steps,
A large rolier-Dall Surrounded
by ball-bearing stabilisers is very
easily steered Dut is sensitive to
irregular surfaces. The trolley
alrangement of two fixed wheels
and a steered castor is the
minimum necessary (OF Stability.
slinging the load inside large
driving wheels is an attractive
idea, bul it raises the centre of
gravily and lessens stability
KEVIN JONES
DIVIDE AND RULE
In this instalment of our LOGO course, we
introduce a number of turtle graphics
procedures that produce interesting shapes
by the use of recursion. Some of these —
shapes have very strange properties indeed,
as they were’ the inventions of
mathematicians intent on demonstrating
Our first program is acacia to ane ee alaues:
To start with, we can simply draw a trunk with a
right and a left branch. The branches may then be
formed in exactly the same way (although they will
_ besmaller), with a central main stem and right and
left twigs. If this process is continued, a tree shape
will gradually be built up. This is a good example
' of the way recursion can be used in LOGo.
Our procedure for drawing such a ‘binary’ tree
requires two inputs: one for the length of the trunk
and the other the ‘level’ number. The length of the
branches is halved at each level away from the
trunk.
TO BRANCH :LENGTH :LEVEL
IF-LEVEL = 0 THEN STOP
FD :LENGTH ys
By eens : |
- BRANCH (:LENGTH / 2) (:LEVEL = 1)
RT 90: | :
BRANCH (:LENGTH /2) (LEVEL - 1)
LT 45 | |
BK ‘LENGTH
END.
Notice that the procedure is ‘state transparent.
This is important as otherwise the ‘state’ of the
turtle (its position and heading) would be changed
each time the procedure calls itself, making it
impossible to continue the drawing. :
It must be admitted that this procedure
produces an unrealistic tree — to make it more
interesting, the procedure can be modified in
various ways. Here’s a version that draws three
branches, each of a different length, at each level:
TO BRANCH 1:LENGTH ‘LEVEL
-IF:LEVEL = 0 THEN STOP —
FD:LENGTH ‘ies
LT 30 | veo
BRANCH 1(:LENGTH /3) (:LEVEL-1)
SPR AO: ee eee ee ea
BRANCH1 (:LENGTH /2) (:LEVEL - 1)
RT 50 os |
BRANCH1 (:LENGTH / 1.5) (:LEVEL - 1)
LT 60
BK :LENGTH
END
: Try other modifications to produce 1 more lifelike
us ees.
CHEQUERED POLYGONS
The following procedure draws a square, divides it
into J then divides each part into four, and so
on: 5 :
TO BOARD :LENGTH :LEVEL
IF :LEVEL=0 THEN REPEAT 4 [FD LENGTH RT 90]
STOP
BOARD ( :LENGTH / 2) (:LEVEL - 1)
FD (:LENGTH/2) |
BOARD (:LENGTH / 2) (:LEVEL - 1)
RT.90 ae
FD (:LENGTH /2)
00 ee
BOARD (:LENGTH / 2) (:LEVEL - 1)
~ BK (:LENGTH / 2)
BOARD (:LENGTH / 2) (:LEVEL - 1 )
LT 90 :
FD (:LENGTH /2)
RT 90 |
END
Write a similar procedure that splits a Handle up
~ into four smaller triangles, then splits each of these oh
up into four, and so on.
, SNOWFLAKES |
First draw. an equilateral triangle — one whose
sides are all of the same length. Now divide each
side into three equal parts and draw a new
equilateral triangle on the centre section. Rub out
the common lines, then repeat this sequence for
THE HOME COMPUTER ADVANCED COURSE 623
each side of the new shape, and continue the
‘process. The resultant shape is often called the
‘snowflake curve’ because of its anpeance: |
TO SNOW :SIZE:LEVEL .
_ REPEAT 3 [SIDE :SIZE :LEVEL RT iia
END ,
TO SIDE :SIZE :LEVEL
IF LEVEL = 0 THEN FD :SIZE STOP
SIDE (:SIZE/3)(:LEVEL-1)
LT 60 tas
SIDE (:SIZE/3) (:LEVEL- 1)
RT d20"= | |
SIDE (:SIZE/3) (:LEVEL- 1)
LT 60 | | :
SIDE (:SIZE/3) (:LEVEL- 1)
END
624 THE HOME COMPUTER ADVANCED COURSE.
Notice that SIDE is not state transparent, but
instead has been constructed so as to leave the
turtle in the correct place for drawing the next side.
If this process of division is continued
_ indefinitely (mathematicians use the phrase ‘in the
limit’), the result is a curve that has infinitelength
and yet surrounds a finite (fixed) area! It is possible
to prove that this curve is neither one-dimensional
nor two-dimensional, but is instead somewhere
between the two.
A similar curve may be built up by starting with
a square, dividing each side into three equal parts,
constructing squares on the middle sections, and
so on. ‘ry writing a procedure that does this.
SPACE-FILLING CURVES
The series of curves shown here was invented bya
mathematician called Sierpinski. If the process is
continued in the limit, the result is a curve (a one-
dimensional line) that passes through every point
of the surrounding square (a two-dimensional
shape). There are many other ‘space-filling —
curves’ that exhibit this strange behaviour.
_ The procedure used for drawing this curve is
fairly complex. The level 1 curve is made up of
four sides (shown in blue) that are joined by four
diagonals (shown in red). So the main procedure, -
SIERP, just divides the process into four sections for
the procedure ONE.SIDE to handle one at a time.
Consider just one of the sides. This is made up
of three lines — a diagonal, a horizontal or vertical
line, then another diagonal. At level 2, each
diagonal is replaced by another, smaller, set of
three lines, and the horizontal or vertical line is
replaced by two similar sets of three joined by a
line. The same process is carried out to move from
level to level. :
Here are the procedures for drawing the curves.
Notice how the Loco command MAKE is used to
initialise DIAG:
“STOESIERP <SIDE /LEVEL.”»
MAKE “DIAG :SIDE / SQRT (2 on
REPEAT 4 [ONE.SIDE :LEVEL RT 45 FD :DIAG RT 45]
ENDS ,
TO ONE.SIDE :LEVEL
IF:LEVEL=Q STOP
ONE.SIDE (:LEVEL — 1 )
RT 45 ©
FD :DIAG ©
RT 45 ee
‘ONE. SIDE (LEVEL = 1°)
LT 90
FD :SIDE
a0!
FD:SIDE
EOD +” |
ONE.SIDE ( :LEVEL - 1)
RT 45
FD :DIAG
a oe :
TONE SIDE(:LEVEL= 113
END
s,: * aeaeeieanan
Sierpinski’s Curve -
| replace the ascending line by a broken line with six ©
| the task into two parts — one concerned with going
| to write two separate procedures to deal with the two
Procedure Problems 4
Our illustration shows a series of shapes that in their
limit define a curve that has no gradient at any point.
The first level consists of two lines — one going up,
the other down. To proceed to the next level, we
parts. This rises to half the height of the original line,
then drops all the way down; it again rises to half the
height, continues to full height, drops back to half
height and finally rises to full height again. The
descending line is divided into six sections ina ~
similar way.
LEVEL 1
Try writing a set of procedures that will draw this
series of curves. You should use SETXY instead of
FD and RT. Your top-level procedure should divide
up, the other with coming down. You will then need
parts of the top-level procedure. Remember that —
these procedures may call each other as well as —
themselves!
THE HOME COMPUTER ADVANCED COURSE 625
To Be Reviewed. .
ie arene iitearatad packages to
be reviewed in this series are
Lotus 1-2-3, Open Access,
Symphony and Framework
_ techniques have begun to filter down to home —
enable the programmer to switch between
SUM OF THE PARTS
‘Integrated software? has become o one e of the
fashionable expressions of the software
business. In this article we discuss exactly
what is meant by integration and look at the
advantages and disadvantages such a system
offers. In future articles in this series we will
look at specitic packages. re |
Integration represents one of the at | xaane
trends in software ever. And while for the moment
it applies mainly to business systems, its
micros. An example of this is the Sinclair QL,
whose four software packages encompass the
main principles of integration (see page 502).
The main achievement of integration is to
different packages quickly and simply. In an ideal
system it should not be necessary to quit one
program, return to the operating system, swap
disks and then start up another program. To be
_ effective, the change of application has to be
almost at the push of a key and some programs,
such as the Lotus 1-2-3 and Ashton Tate's
Framework achieve this.
It is also useful to be able to transfer data
between packages easily. For example, you might
create a column of yearly sales figures for your
_ business in the spreadsheet program, then transfer
COURTESY OF MICROSCOPE
IAN McKINNELL
that whole column to the word processing
program where you might be writing the annual
report. You could use the names and addresses in
a database file with the word processor to write a
oid ane ae to all the eee on file. On the
626 THE HOME COMPUTER ADVANCED COURSE
Lisa and Macintosh, this facility is extended to the
point where you can create a freehand drawing
with the graphics program and then move it
straight to a word-processed document.
In addition, all,the different programs should
work in the same way and feel the same in use.
Screen layouts, command keys, prompts, error
messages -— all the aspects of the ‘user interface’ —
should be identical or comparable. If they are not,
the user cannot confidently go from one area to.
another without having to stop and adjust to the
change in operating procedures. This interrupts
the flow with which the software can be used and
does not allow it to be exploited to the full.
A handy side effect is that the package becomes
easier to learn. Having to learn to use five new
application. programs — some menu-driven,
others command-driven, all with different
command formats — is a daunting task for
anyone. But if they all work in the same way, you
need to learn one only. This feature is known as
‘commonality’ and is often referred to when
integrated software is discussed.
We have established then that integrated
software involves three design principles: the ease
of switching from one application to another;
freely interchangable data; and commonality of
format. This contributes to making the computer
more accessible to the average user whose needs
can be met with two or three software applications.
‘It will also undoubtedly increase the popularity of
the personal computer as it becomes more
efficient and easier to use.
However, integrated software also has. its
disadvantages. Primary among these is the fact —
that integrated software packages need large
~amounts of RAM to operate. Imagine trying to fit
a word processor, spreadsheet, and database —
the three applications that are most commonly
integrated — into 16 or 32 Kbytes. It can probably
be done, but there would not be much, if any, room
left to store data. It is this problem. that restricts
integrated software to machines with large
memories: in general, to computers with 128
Kbytes or more. Of course, programs that are ©
integrated can share some routines, so disk storage
operations and other housekeeping activities need
only to be written once. Nevertheless, each
application has its own special requirements, and
these take up space in RAM.
A second weakness of integrated software is an
_ offshoot of the same problem of storage. To save
on the amount of memory a program requires,
_— software writers take shortcuts with the individual
applications. A word processor that is built into an
integrated package with two or three other
—— +) ae =
%
applications cannot be as thorough and as
complete as a word processor that stands on its
own. The main reason for this is that a stand-alone
program can take up as much memory by itself as
the integrated programs take together.
One example can be found with two programs
that run on the IBM PC and similar computers.
Multimate is a program designed around the
software that is used in Wang dedicated word
processing equipment. It has many options for
creating and formatting text that are not found in
smaller programs, which makes creating very large
and complex documents fairly simple. Multimate
by itself requires 192 Kbytes of RAM to operate.
Lotus 1-2-3, an integrated word processor,
spreadsheet and database program, also requires
192 Kbytes. Yet the same space used by
Multimate for one application must now handle
all the software required for three complete
programs in Lotus. As a result, the word processor
in Lotus 1-2-3 is limited to simple memo writing.
A third disadvantage of integration also arises
from one of its strengths. It is important, as we
have seen, for integrated programs to look alike,
so they are easy to learn and _ operate.
Unfortunately, certain compromises have to be
made by the software writers for this to be
possible. The best way to operate a spreadsheet
Rules Of Play
er ee ee ee er
Mibianiietenty tialghdige anihdt Pa edtat Atel tendsis/. oa la atay ep iaierald Ne: Merge), Woe oh. tn
fal plawe Pa ee free he amas 2 Seite, eel Bator a ye cal rep Rant tey Kea swy Ber myribe Wi ya) aay a 8
PPA oie Wea, eat kc er ee
eRe oa ee er ee
cee ee eee
Cher een Tet Pin Mts ae ee
eee ee we we
Sigg ai Fa ad oN alee
Sewcetestecesene
Seeeseerceeeeceseceseses. hh nara hrae
ee es
Pe ere ee ne er
sb ee wae
ee
ee we ae
rae eet ap rr ne sea
S69) Ge
a ee
er er er
aeoee
teeeee
Ceesee
CLEMO SO COCO RESSEROECESOESCESOS
SHCES OSC CERO.
SEeeereseese
eae hs ter ier ee ek)
FOV EROOM
SEK COREE SS ES
seaceasene
Coeds ees
eeesve
eeooe
eaeee
Lees
eee
$6 Cee
eee ewe:
CERO oe
.
PORES A ASRS CO ORS CO ES
Fully Featured
Integrationis the operating © .:#::s:nfiii:
principle at the heart of Apple's
Macintosh on which these
illustrations were produced.
Multiplan (the spreadsheet),
MacWrite (the word processor)
and MacPaint (the graphics
program) communicate directly
through the operating system so
that three separate applications - .
become effectively one ‘hal L lt 1 p ] i | mn
Common Code
Commonality of format between —_
- integrated applications is clearly :
demonstrated in these
_ Spreadsheet and word processor
displays
f
@
egeeee
ovanone
Oaeene
ates:
= FOU wren Re ¢
BARS ES
ie mo EE he > R
: ; S60 Umate you a 25th 3 .o ji:
might not be the best way to use a database or | 20m ,Ms TM estog MEM. en, A
° F 26 TOR ete ee
word processor, so elements of the optimum | = Piaget —r—“—iC—rSH
: 3 420 “PC goto _ B+caort
design for each tend to be blended into a usable | oe ee a
; S00 Ge-wg \SRLiR) asSGie ee
j 2 he i Bul |
mixture. Microsoft found this to be a problem —“—iS—Sé« UE
eats oe 6gi;5 Gu cin Right
when designing a stand-alone word processor, | — SUD Totp eo, OSER ay Dow
Suaeet sort.
Microsoft Word. The company wanted the screen “mmc.
display and the program’s operation to be oe «si(<‘ ‘és * Me: OM
compatible with their hugely — successful
spreadsheet, Multiplan, so it would be easy to
integrate the two programs. Microsoft included
the same on-screen menu in Word that Multiplan
users found so helpful, only to discover that the
writers who needed a program like Word disliked
having a menu on the screen all the time.
The point to remember about all software is that
it has to do what the user wants. If a person has
several tasks to do, like letter writing, simple
accounts, and mailing lists, integrated software
can make the job much easier. But there are
sacrifices, and someone who wants to write a novel
or very lengthy company reports on_ his
microcomputer may have to continue to use
BER cose.
De ica Wa ae a ORR BEN, Cia
ee cia
per ee
apse at WN $v \ ts RO -- ca e e a
Re
Aa
ee
bes
ihe
ast &
ye pe
wwe 18
“Transferred Charges
separate, stand-alone word processors, ni fas neen moved directly.
ie irectly
spreadsheets, and database programs. from the spreadsheet into the
Nevertheless, as software writers learn more about
compressing computer instructions into smaller
and smaller spaces in memory, and the memory in
home machines starts to inch its way upward,
integrated software will become more and more
important to the home user as well as the business
user. As a hint of things to come, two under-£500
computers are being sold with integrated software:
Sinclair’s QL, and the Commodore Plus/4.
In future instalments of this series,.we willtakea _
closer look at some of the integrated programs that
are having a large effect on software development.
word processor, demonstrating .
the importance of data
compatibility and transfer in
integrated software
We will examine two distinct approaches to
integration: one exemplified by Lotus 1-2-3 and
similar programs, in which the applications,
although working together, look very much like
typical computer programs have always looked
_and the second type found on machines like Lisa
and Macintosh, where the whole operating
environment is designed for integration. —
THE HOME COMPUTER ADVANCED COURSE 627
IAN McKINNELL
FLOPPY DISK
-In considering the development of RE in
the post-war period it’s easy to assume that the
techniques of Large-Scale and Very Large-Scale
Integration (LSI and VLSI) have been the fuel,
- and the cheap mass-produced microprocessor -
chip the engine, of the microcomputer revolution.
Of equal importance, however, has been the
_ development of cheap, fast, dependable back-up
storage — the floppy disk. Single-drive units
costing about the same as a microcomputer that
are capable of storing up to half a Megabyte of
data or programs on a disk costing a couple of
pounds make an over-priced electronic toy into a
credible data processing system.
Inevitably in the growth of microcomputing,
several disk formats have developed: the 8in
diameter floppy, the 54in mini-floppy, and the 3in
and 33in microfloppy. All consist of an oxide-
coated thin (less than 0.5mm) flexible plastic disk,
ima protective jacket. This jacket is never removed,
and is pierced with a radial slot or window that
gives access to the disk surface. In use the disk
_ spins inside the jacket at around 300 rpm, while
the drive read-write head moves backwards and >
forwards in the window. This allows reasonably
fast access to every spot on the surface. Another
slot in the jacket is called the write-protect notch:
the drive unit checks that this notch i is open before
writing on the disk.
The read-write head is similar to a tape-
recorder’s; it writes by changing the alignment of
the magnetic domains in the disk’s surface, and
reads by sensing those alignments. Information is
written along concentric circles on the disk surface
called tracks, divided into 20 to 40 sectors. High-
quality, or double-density, disks can have up to 80
tracks, while single-density disks have 40. The
boundaries between track sectors can be marked
_byphotoelectrically-sensed holes — one per sector
Demo Disk
The illustration shows a 53in
floppy disk, with the read-write —
window, the sector index hole and
the write-protect notch en,
visible
_— in the inside rim of the disk, in which case the
disk is hard-sectored. The alternative — soft-
sectored — disks have just one index hole, which
DAVID WEEKS
marks the start of the first sector on every track,
Sa thea sector boundaries being aay
De se AYO RE URI TANASE RETNA
_ 628 THE HOME COMPUTER ADVANCED COURSE
structure ©
FLOWCHART
Any graphical method of representing the
interactions of control or information in a program
or system tends to be called a flowchart, though
_ many such diagrams represent relationships rather
than flows, and so should really be called “process
diagrams’, or ‘data graphs’. The commonest form
of flowchart comprises boxes of various shapes
representing program processes such as input/
output, decision-making and data processing;
these boxes are linked by arrowed lines that show
how control passes from one process to another in
the program. Most self-taught programmers use
‘this type of flowchart, but in recent years it has
been discarded by professionals and academics
because it allegedly distorts or conceals program
when used as __ descriptive
documentation, and because it encourages badly
structured program design. In general, the graphic
approach is more and more discarded in favour of
precise requirements specifications, data
definition statements and function description
_ languages.
FLOW CONTROL
Tn any real-time data communications application
the receiver and the sender are likely to have
different optimum transmit/receive rates; in order
that slow receiving devices are
overwhelmed by fast transmissions, some flow
control strategy must be employed, either by the
transmitter, or by the transmission network
controller. The simplest strategy is known as end-
to-end control, in which the amount of data sent is
limited to the capacity of the receiver. Another
strategy is called hop-by-hop — the amount of
data sent is limited at every step through the
transmission network by the capacity of the node
or link smb the information.
FORMAT
Any pre-defined structure is a format, but in
computing the term usually refers to disk or
instruction formats. The former refers to the way
in which the pattern of tracks and sectors is
physically distributed on the surface of a magnetic
disk (see page 124). Disks used by one
manufacturer’s disk drives may well be unreadable ~
to other drives precisely because of this. This
_ problem is eased somewhat by the emergence of
common operating systems such as CP/M and
MS-DOS: software packages written for these
systems often share a common disk format. To
format a disk is to prepare it for a particular disk
_ drive; this destroys any information on the disk.
Instruction formats describe the syntax of
instructions or commands, For example:
RENUMBER startno [,endno [,inc] ]
indicates the spelling of the command word, the
nature of its possible arguments (first line number,
_ end line number and increment), the delimiters
(the comma), and the variant forms of the —
command (anyihine in square brackets is
: Setenn)
not —
“P
CUDDLY TOY
For Commodore 64 artists the Koala-pad
offers an easy way to produce high-quality
graphic displays and overcomes the problems
associated with graphics generation on this
machine. Light, compact and easy to use, this
peripheral device enables complex screen
pictures to be built up at the touch of a finger.
Despite its ability to produce excellent graphic
effects, the Commodore 64 has so far not been
provided with the high-quality graphics peripherals
that have been produced for the BBC Micro. This is
probably a result of the difficulties associated with the
production of high resolution graphics on the 64 -
difficulties that have deterred manufacturers from
producing such a_ device. Now, however,
Audiogenic has begun importing a graphics pad
made by the American company Koala Technology
that allows Commodore 64 owners easier access to
the machine's high resolution graphics capabilities.
Unlike similar touch tablets such as the Grafpad
(see page 169), the Koala-pad is light and compact,
measuring only 20.5 by 16 cm (8 by 6in). In the
centre is an 11 by 11 cm (4 by 4in) carbon fibre square
that covers a touch-sensitive membrane that is
similar to the Spectrum keyboard. By simply pressing
a finger or a pen onto the membrane, the user can
guide a cursor around the screen. This is in contrast to
other graphics tablets, which require a special ‘stylus’
to complete the circuit.
The membrane consists of two sheets of
conducting wires — one in the horizontal and one in. .
the vertical axis. When the membrane is pressed, the
pad detects which wires are in contact and sends the
resulting co-ordinates to the computer. Above the
touch membrane are two buttons, one of which must
be pressed when the user wishes to colour in a point
on the screen or select one of the various paint
options that are available. Either button may be used
— presumably this is to cater for both left- and right-
hand users.
COLOURING IN
The Koala-pad connects to the computer via the
joystick port, and Koala Painter (the software needed
to work the pad) is loaded from disk. Once loaded, a
display of the various options available appears on
screen. At the bottom of the screen is the ‘palette’
containing 16 ‘true’ and 16 ‘tinted’ colours. The tints
are built up by colouring alternate pixels in different
hues, giving the effect of shading. Above the palette
are eight boxes containing the ‘brushes’. These simply
consist of various shapes that may be plotted on the
screen, and range from a single pixel to combinations
of pixels and lines. Surrounding the brushes are the
various options for drawing lines or shapes on the
screen. These are selected by the user pressing on the
pad membrane and thus directing a cursor arrow.
When the arrow points to the desired option,
pressing one of the Select buttons on the pad brings it
into effect. The option flashes to remind the user
which mode is currently in use. The Koala-pad
provides the facilities to produce single lines, rays
(lines drawn from a single point), frames and circles.
Blocks of colour may be added by using the ‘box’
(coloured squares) or “disc’ option (coloured circles).
Further colouring is achieved by using the FILL
command to fill an enclosed area with a chosen
colour. Colours are altered by using the X-COLOUR
command. oe | :
Identical figures may be drawn simultaneously by
using the MIRROR command. This divides the screen
into four sections, with the cursor restricted to the top
left-hand quarter. Anything plotted within that
THE HOME COMPUTER ADVANCED COURSE 629
Hand-Held
Complex and sophisticated
graphics screens can be built up ©
in a few hours using the easily
understandable menu-driven
software. Unlike many similar
graphics tablets, the Koala-pad
can be held in the hand while
being operated
_ KOALA-PAD/HARDWARE ()}
IAN McKINNELL
Take Your Pick
The main menu of the Koala-
pad consists of boxes
containing both the name and
an explanatory icon. Although
the icons are intended to aid
understanding, some of the
illustrations are perhaps.
confusing. The cursor arrow is.
moved into a box and the
‘Select’ button is pressed. The
‘name of the selected box will
flash to remind the user which
‘mode is in use
/
IAN McKINNELL
Highly detailed pixel plotting is achieved by using
the ZOOM command. The user may choose any part
of the screen, and this is then displayed as an
expanded ‘window’ at the bottom of the screen. The
individual pixels are displayed as eight by eight pixel,
character-sized squares. This feature makes the
production of fonts and sprite-sized figures quick and
simple. These figures are then placed anywhere on
the screen by using the COPY command; this allows
the user to define an area of the screen, the contents
of which are copied to any other position.
After these options have been selected, the cursor
arrow is moved off the screen and the Select button is
pressed. The screen then changes to the ‘canvas’ on
which the required picture is built up. By moving the
cursor arrow and pressing the Select button, lines and
shapes may be drawn anywhere on the normal
Commodore 64 graphics screen. |
MINOR NIGGLES |
The quality of the graphics produced by this
device is excellent, rivalling high resolution screens
produced with commercial software. However, one
disappointment — also shared by other graphics
packages — is the quality of the freehand DRAW
command. The membrane matrix resolution does
not match that of the 64’s high resolution screen, so
the user’s stylus (or fingertip) will often not be
directly over a grid intersection and may in fact be
triggering two points at the same time. The
computer, in trying to interpret this, will plot a point,
which unfortunately is not always at the position
intended. This can result in what was planned as a
630 THE HOME COMPUTER ADVANCED COURSE
quadrant will automatically be copied to the
corresponding area of the other three quarters.
straight line appearing as a messy scrawl. Another
criticism is that, apart from the ZOOM command,
there is no option to change the colour without
returning to the main menu. But these are minor
complaints that are more than offset by the speed at
which the LINE and FILL commands are executed.
A further software limitation that could have been
better thought out is the method used to erase
mistakes. When a mistake is made, it is removed from
the screen by use of the OOPS command, which is
accessed from the main menu. However, using OOPS
will erase all the work that has been performed since
the user last exited from the main menu. This means
that perhaps half an hour’s work may be erased,
simply because of a single error. The alternative is to
erase a mistake by using the ZOOM command and
correcting the error pixel by pixel, which in the case of
a badly placed disc or box could take some time. A
welcome amendment would be to restrict the extent
of the OOPS command to the last press of the Select
button rather than the last exit from the main menu.
As may be suspected from a device that plugs into
the joystick port, it is possible to use the Koala-pad as
a joystick, thus allowing users to access the Koala-
pad from their own programs. The position oi the
cursor can be obtained from Basic by PEEKing
locations 54297 and 54298 for the co-ordinates of X
and Y respectively.
Screens may be saved onto disk and can easily be
transferred to the user’s own programs, allowing the
development of ‘Hobbit’-style adventures with text
at the bottom of the screen and a picture above. By
using the Koala-pad it is possible to save and recall up
to 16 different eight-Kbyte screens on a disk.
Although it is not possible to load a screen from disk
directly into screen memory, Koala Technology has
provided a program in the Koala Painter user guide
that enables screens to be transferred from the area in
which they are loaded to the screen memory.
The maximum resolution of a saved Koala Painter
screen is 255 by 255 pixels if it is included in a BASIC
program, although higher resolutions may be gained
by using machine code. This limitation may cause
problems as the Commodore 64 high resolution
screen is actually 320 by 200 pixels in size. The
Koala-pad is restricted to a maximum of 255 pixels
because this is the largest number that can be
addressed by one byte — to address a full screen
would require 16-bit addresses. Unfortunately this
may result in the user losing a portion of the display.
This is because, when the screen is not actually being
displayed, it will be stored somewhere within user
RAM. Therefore the eight-Kbyte screen, together
with the colour information, must be transferred
from its location in user memory to the high
resolution screen memory commencing at location
55296. , :
However, any minor niggles apart, it must be said
that the Koala-pad is a very useful peripheral for
anyone wishing to produce high resolution graphics
screens on the Commodore 64. It is a pity that the
software is supplied on disk only, as this will
inevitably limit the device's appeal. But for disk
owners, this would be a worthwhile investment —
particularly for the artist or the adventure-writer.
5 THE HOME COMPUTER ADVANCED COURSE
IAN McKINNELL
Though most successful commercial games
are fairly lengthy, and written in machine
code for speed, it is possible to write an
entertaining game in BASIC. The game that
follows is fairly simple, and indeed takes up
only 35 lines of Basic, but is still good fun to
play. Furthermore, it is a two-player game,
so is less anti-social than most!
The game is called ‘On Your Bike’ and is based on
a scene from the classic Walt Disney film Tron. It is
a contest between two opponents that requires
skill and fast reactions and takes place in an
enclosed arena. You each have a bicycle that
travels at an incredible speed and cannot be
stopped. Your only control allows you to turn
through 90 degrees at top speed.These bicycles
leave solid walls of light in their trail, and the object
of the game is to force your opponent to crash in
the ever-tightening maze you create as you Zoom
around the arena.
The game has been implemented on the ZX
Spectrum, which is not known for the speed of its
pasic. As this is an action game, the program has
been designed for speed rather than elegance,so
much of the listing may seem a little unstructured.
632 THE HOME COMPUTER ADVANCED COURSE |
ON YOUR BIKE
Subroutine calls; and other structured devices
have been avoided as they would have sacrificed
execution speed.
The first stage is the design of the arena and
score display. As you can see this is fairly simple,
which contributes to the shortness of the final
program.The only point to note is that the border
of the arena is now one character in from the
usable screen area. This is to ensure that the
graphics resulting from a collision with the arena’
wall do not go off screen:
10 LET p=0: LET q=0
100 BORDER 0: PAPER 0: CLS
110 PRINT AT 0.1; INK 6; “Bike One=”;
120 PRINT AT 0,19; INK 5; “Bike Two=”; p
130 INK 2 |
140 PLOT 8,8: DRAW 239,0: DRAW 0,159
150 DRAW -239,0: DRAW 0,-159
The arena has been drawn in red, and we have
chosen. yellow to represent bike one, and cyan
(blue) for bike two. The variables p and q hold the
current score for the two contestants.
The next stage is to initialise all variables, and
here we have to start thinking about how we are to
implement the main action of the game. The
action for a single bike is fairly straightforward,
and is shown in the flowchart. Using POINT we
check if the bike’s current position is occupied, and
move to the collision routine if it is. If it is not, we
move into that position using PLOT, and then read
_ the keyboard to check for any change in direction.
Our position is then incremented by one in our
current direction, and the cycle begins again. We
therefore need four variables: two for our current
x and y co-ordinates, and two for our current
direction along the x and y axes.
However, we are dealing with two bikes moving
at the same time. An elegant solution would be to
use four two-element arrays, x(2) and y(2), for the
positions for example, but this would slow the
game down so we have to use eight separate
variables:
200 LET x=40: LET y=88
210 LET m=215: LET n=88
220 LET a=1: LET b=0 ©
230 LET i= -1: LET j=0
This sets the initial positions of the bikes, and sets
them moving towards each other one pixel at a
time. The basic action of the game is then fairly
simple to implement:
400 IF POINT (x,y)=1 THEN LET col=6: GOTO 700
410 IF POINT (m,n)=1 THEN LET col=o: LET x=m
LET y=n: GOTO 700
420 PLOT INK 6;x,y:PLOT INK5;m,n
eS SSS SSS SSS SESS
4 SS ee en ane
— % Se \
The only confusing point is perhaps line 410,
where the variables for bike one are set to those for
bike two, and a new variable,col, is introduced.
This is so that a single routine can be used for the
collision action, where x and y are simply used to
indicate the point at which the collision takes
place, and col sets the colour.
The routine for checking the keyboard has to be
fast, but we regretfully have to use IF... THEN
statements that are fairly slow. However, we can
use the fast IN command to read the keys. The
control keys chosen are Q and A, which control
upward and downward movement for bike one,
and P and ENTER for bike two. Left and right are
X and C for bike one, and N and M for bike two.
(See page 366 for a full explanation of how blocks
of keys relate to bytes in memory.)
All that remains is the collision routine, and the
updating of the scores. An expanding series of
concentric circles, centred on the point of impact
was chosen, with radii of four, six and eight pixels:
This finishes the game, with the last statement
looping back to the initialising procedures at the
beginning. The game could, however, do with a
starting procedure to make it more friendly to use:
300 PRINT AT 10,5; INK 7; “PRESS ANY KEY TO
START”
310 IF INKEYS= “” THEN GOTO 310
320 PRINT AT 10,5; “ j
This gives you a break between consecutive
rounds. All that remains is to save the game to
cassette, preferably using SAVE “OnYerBike” LINE 10
so that the game automatically runs as soon as it is
loaded.
The game could obviously be made more
exciting, with instruction screens, loading screens,
a one-player option with a strategy routine
controlling the other bike as we have suggested,
sound and better graphics. But certainly the latter
options would make the game unplayably slow. In
a future instalment we will rewrite this game in
“machine code to demonstrate its full potental.
Fitting In
computer is Player 1. The ©
program section that checks
input is bypassed, andthe —
algorithm in the code given
allows Player 1 to continue
One Hand Clapping —
_ movingina straight line until that
In the one-piayer version the
Player 1 $ command keys for
generates an illegal move, or
Player 2 moves. In the latter case,
_this move is mirrored or
duplicated, and then checked for
__ legality. Whenever anillegal ~
_ Player 1 move is generated, the
program looks for legal moves at
tight-angles to the illegal move -
direction: if none is found then
the position is hopeless —
_ to the end of lines 550 to 570 -~
There are many ways of
implementing a one-player
__ version of this game. The changes
_ we suggest make it possible fo |
_ choose between the one- and -
two-player versions at the start of
every game. Itisntdifficultto
__ invent satisfactory algorithms for -
playing this game, butit’s
extremely difficult to implement |
them in BASIC without ne
down the game considerably.
_ Make the following changes to
the program:
20 LET keybd=500:LET
pt—1.LET umoved=0: -
RANDOMIZE
260 PRINI Al 10,5; No. of
Players (1/2)?
Z2/OLEL aS-iINKEYS IF 3 3=—t=w
as=< > 1 ANDaS< ye
THEN GO 10 270
280 IFINKEYS< >*2” THEN
_LET keybd=440
These lines give the user the
choice of game types, and
implement that choice by
_ accessing either the one-player
Stratagem between lines 440 and
A460, or the standard two- ae
version between lines 500 and -
5/0. Our strategy is contained | in
these lines:
430 GOTO keybd :
440 LE] pt=SGN (RND-0.5): IF
umoved=pt THEN LET a=pt*):
LE] b=pt7i: LE] umoved=0_ ©
450 |F POINT (x+a,y+b)< > 1
THEN GOIO 540
460 LEI pt-SGN (RND-.5). LET
a-a PELE] b-b’ ot LEI d-a
LET a=b: LET b=<d: IFPOINT
(x+a,y+b)< 7) THEN GOTO
oC | |
“ABO LET aa: LET b=b: Goro.
0 Ct
540 IF IN 57342=190 THEN eT
_ i-0: LEI j=1: LET umoved= 7
_and similarly add:
- LE] umoved=1
One-Player Option
This simplified flowchart shows
the program structure with only
one player. Each process is
repeated in the full two-player
game
LIZ DIXON
THE HOME COMPUTER ADVANCED COURSE 633
SANOP NIAIY
a © a q See Seren
SSE 5 os
Pau ges SSEES9-2
eae eS Se ees ee 2S5 oe ae5
5 5" BRM. “Bb & O09 “48s 8 A§ |
A on ° 8 ¢ 0.9. S » SS eae —4S 8
oS Slee ogee g egeey8es :
eeiEgoycog225 SSEYEBE 8 _
: 66. 2 f= BVvornd a. “ arte eos
Aa aeaHeeer oed ai Sose eens
| A Re SRPrLLE » aig FES S25 9
Ao MS dae SOLS 5 B2o8
SosSehob Soe 2 x“ . : Pe oD oS
Soceargtre aa Ps 9A =
Zs Lo o SA od, 5 3 Besse Eas
> 2Ssges gana £ ie ieee fenees go Bee3 58
| ESR SORE ws oho eh Bg: Sa SEELSY _
eee er S28 eee Se 59+ sed eos
a rit: i tee} SaSR5 88
CY ees eresS2ibges bese pySE SES
| S-o. iD) Meo Wor Se a) =
egegceags. oe am PReR ETPSE BO EZ TS of
= WN O = i) z + OZ oe o) ron] ~~
. ea oP EP SSC ED Eg fHt: ae me fy Dy é Or.) Ss
meet. sinwo SL Gogtake 3 ~ ees a0 = o)
E Ea o® ~ ES Bo dt FUELS cone tok pESSeg8
SRE SS Ss © sds Bm IEKzZS Yonzese wy FE eng es
BO: = OS's 2. oS s Hoonro & SE VES SS 5
7 SeESECES gag riots ccssseg GRRE ENS
E GQ. Da oOo B c= © A See SS an ee :
oe Be OR SESE CES Dp ented : S25
OUR HBS See fs aS
BSLSELS gwous sss ga ks
SP ESO. Eat. 8 EAS
GE |SSE 2522223 5 Ss S8yERS
eSaeee Sago @ : BREYER ES BBS
=,2=se Sees eg i ERSs 6S 8ee
Seeges Bec RBS ee2 8s. Ee Oe ee.
( ) Zoe ee goc8S ge cagoR ZEs 22
SS os BO, = “2S kaa RSs Sak &
a eS PLO KD : Ou.
giteee ire Leeper Pos ae
| . = VON
: Senses SoOtL2oh¥s ERR a? S8583
eo" 2S BE MOR ESEE YES = 2s oe %
BE Yo 8s & > oO >> oD ras Sos & fe
LJ GHEE. s GRRE SeESER AF Sxees2 :
oa 2 gece g2uabaachs esse Wes eS z
| Y = — = be | wo Soo as 5
ae 25 8s DO. 7 aU = Sool ee [2]
iY 9) =D) — oe Q) cu Sas & a oe O
Ses ESz =| Sgt aose as O uw Ovsgss
oe Se m S [2D 5 = lao Fo RS os 2 wi ODO E
PS wg : Osea MA. ‘Ge O'S ao 25. Rs >
‘ n=: SEY sees eghage 8 Sseeoe
SRSESES| cB BE AS ESD EOSS =<5oo® a
: SE TESTE PEpesyTeeearass 9 Ag Ho Bo
ree a i Bre kes Bobo kk Q2oeee 2
, = P= p-5-0- hon a Pog. ss kee :
ea RESaE2 Ii ae
634 THE
Rn I
the joystick. We can summarise the actions of the
joystick’s switches on the contents of the joystick
memory location as s follows:
You may also have noticed that moving the
joystick diagonally can cause two switches to close
simultaneously. Although we do not require
detection of diagonal movement to control, our
vehicle, the results of such movements on the
joystick memory location are as follows:
The following program uses a joystick to control
the movements of the twin motor vehicle. The
vehicle should be connected to the output box in
the same way as on page 586 and the joystick
should be plugged into games port 2, located on
the right-hand side of the Commodore 64.
1@ REM CBM 64 JOYSTICK
20 DOR=56579:DATREG=56577
3@ POKEDOR,255:REM ALL GUTPUT
4@ JOY=PEEK(56320):REM JOY PORT 2
5@ GOSUBI@@@:REM TEST JOYSTICK
60 POKEDATREG,@:GOTO4a@
98 :
100@ REM TEST JOYSTICK S/R
19095 IFJOY=127THEN POKEDATREG ,@
191@ IFJOY=126THEN POKEDATREG,5S
1920 IFJOY*#125THEN POKEDATREG, 10
1030 IFJOY=123THEN POKEDATREG,6
1049 IFJOY=119STHEN POKEDATREG,92
105@ IFJOY=111THEN POKEDATREG,@:END
1960 RETURN
BBC MICRO
The BBC joystick i is an a device relying on n 3
two potentiometers to provide information about
the up/down and left/right movements made.
The essential difference between a digital joystick
and the analogue type used by the BBC Micro is
that the latter gives information about ‘position’ _
within given limits, whereas the former gives
information about direction of travel only. The
joystick potentiometers work in the following
manner.
A potentiometer iS essentially a resistance :
across which a voltage is applied. A third —
connector to the potentiometer can move along -
the resistance taking a fraction of the supply —
voltage. This fraction depends on the position of
the moving connection. On a linear type of —
potentiometer, if the moving connection were
positioned halfway across the resistance, then the
voltages tapped off would be half the supply
voltage. Thus, by moving the central connection,
any voltage between zero and the supply voltage
Sid AO sey the ch OO
cH2 ov GROUND CHa ov
~ -FB2
can be obtained. Turning the volume control on a
radio or record player is essentially moving the
middle connection across the resistance of the
volume control potentiometer. In an analogue
joystick the movement of the middle connection is
made by moving the joystick handle.
BBC Micro joysticks are generally supplied in.
pairs. The BBC Micro’s analogue port
connections for joysticks 1 and 2 are shown in the
above diagram.
A reference voltage is provided by the micro
“across each potentiometer and the middle
connection’s tap-off voltage is input through two
channel inputs. Channel 1 is used for the input
from the left/right potentiometer : and channel 2 is
‘used to accept input from the up/down
potentiometer. The fire button i is a simple make or
: break switch.
Once the polediomene sits: have ‘bec
accepted they must be converted from analogue to
| 5 digital form by an_ ‘internal converter. This
~ conversion is done by comparing the input voltage
with the reference voltage and conversion time is
around 10 milliseconds for each channel read.
Once the joystick input is in digital form we can.
use the values to control our vehicle.
Input to the analogue port can be read from
BASIC using the BBC Basic command ADVAL. The
value returned by ADVAL is in the: range 0 to 65520,
the upper limit corresponding to an input equal to ,
the reference voltage. Reduced input voltages will
produce correspondingly smaller numbers until —
an input voltage of zero volts will produce avalue ©
determined by the number in a bracket after the
keyword. Thus ADVAL (1) will read channel 1 and
return a value in the range 0 to 65520.
THE HOME COMPUTER ADVANCED COURSE 635
Analogue Reflections
BBC Micro joysticks are usually -
supplied in pairs, going into a
single connector. The analogue .
port pin-outs as seen from
outside the machine show that
joystick 2 is connected in an —
exactly similar way to joystick 1
Single joysticks may be
connected in the place of either
of zero returned by, ADVAL. For our simple =
application we are only really interested in the two.
limiting values. The channel read by ADVAL is
y
ee
rans
oe,
- ADVAL(0) performs two different functions. The = 2 = . |
eas | least significant two bits correspond to the fire,
| ites - buttons on joystick 1 and joystick 2. X=ADVAL i R |
ahs | AND 3 will return a value of one if joystick 1’s fire ‘2: ©. ..-- A eT ee alee
BEF FPROCtest Jorstick
channe |= Lf gah
| | button is pressed. X=ADVAL(0) DIV 256 will give the 148 UNTIL channel <>@:REM KAIT FOR CONVERT
1S8 TF channel= HEM PROCtett right
: | number of the channel that last completed an A- ise 1F channei=2 LEN PRUCWO dow ho. oS
? yn 7@ ENDPROC 3 aes |
a i to-D conversion. a |
| . 7 _ As conversion of each analogue input channel
me, eR takes about 10 milliseconds, then to processeach 277 TSS og, 7 | | |
ne | : | , of the four channels will take 40 milliseconds. In 228 iF joywai<iaa THEN ?DATREG=7 7
) icati we ) 238° IF joyval?440@8 THEN ?DATREG=4
ome _ our application we use channels 1 and 2 only. 225 ¢;,.2=anuaice> AnD 3
| a _We can cut down on wasted conversion time by 258 FRINT?DATREG, channel, joyval
“ “fs : ° 248 UNTIL¢ jorva | OND joyval 64408) ORF fire=
o , _ specifying the channels that require conversion. 37, er oe ies
ae | This can be done by using *FX16,2, which enables 280 ENDPROC ie | ,
age channels 1 and 2 but disables channels 3 and 4. a6 ber pRocup down | ee Bip
? ) | The following program combines all this 21% FEFEAT | | - aks
| information to control a twin-motor Lego car.
328 jorval=ADVAL( 2) a
a1<¢18@@ THEN FDATREG=14
£4688 THEN PDATREG=3 ey
a ae ; i@ REM BEC JOYSTICK CONTROL ADVAL(a? AND = a
S 2 ODR=&PES?T: DATREG=4-FE4a | - 348 PRINT ?POATREG channel, als
<h 34 ?DDR=255:REM ALL OUTPUT S76 UNTIL¢ govval 188 AND J > OR fire= |
7. % 46 REM EMGGL SiGe : 328 PDATREG=6 |
Sa #Fx¥14,2— 358 EMDPROC |
: : , 4a REPEAT
fa P
636 THE HOME COMPUTER ADVANCED COURSE | |
ee eee ee
——————————aaa——aoooaeEeEeEeEeEer
JUMP LEADS
“indexed
addressing on the 6809 processor, we now
consider how indirect addressing is used, and
illustrate this by describing routines to write
characters to a screen display. a
Following our examination of
| First of all it should be stated that ia anect iaddaccite
is not a separate addressing mode in its own right but
is an additional feature that may be used in
combination with most other modes; it is really a
further stage in calculating the effective address (the
address from which the data is actually to be fetched).
The effective address is calculated in any of the ways
we have described (by direct access, by indexed
addressing, or by effective address calculation), but if
indirection is specified then the contents of the
address so calculated and the next consecutive
memory location are treated as an address. It is this
address that becomes the final effective address, from
which data is loaded.
For example, if the following values are stored:
Address Contents —
3000 40
3001 0A
400A F2
then the instruction LDA $3000 will load the value $40
into accumulator A, the effective address being
$3000. Indirection is always specified by placing
square brackets around the operand, so LDA [$3000]
will load the value $F2 into A, the effective address
being the value stored in the address that is in turn
stored in $3000 and $3001 — in this case, $400A. The
contents of $3000 and $3001 form a pointer or vector
to the effective address, $400A. Notice the 6809
convention that addresses are stored with hi-byte
before lo-byte: thus $40 is stored in $3000 and SOA is
stored in $3001. This is called the hi-lo convention.
The Zilog Z80 and MOS Tech 6502 processors use
the opposite convention — they would require SOA
(the lo-byte of the address) to be stored in $3000 and
$40 (the hi-byte) to be stored in $3001.
_Indirection can often be most effectively used in
combination with indexed addressing. The
instruction LDA [A,X], which is in indirect indexed
es addressing mode, will calculate an address by first
adding the contents of A and X and then using the 16-
bit value that is stored at this and the next location as
the effective address whose contents will be loaded
into A.
The 6809 has, if fact, me use for indirect
addressing than most processors (both 6502 and Z80
programs use it frequently) because of its wealth of
indexed addressing modes. There are, however,
situations in which indirection can be very useful —
one of these, which we will deal with at greater length.
in a future instalment, is the use of peripheral
interface devices. Motorola processors, unlike Intel’s
8080 and 8086 families, have memory-mapped I/O
(Input/Output). The communications registers in
the interface devices appear in the system’s main
memory map, and values can be stored to or loaded
from them as if they were any other memory
locations instead of being, effectively, a channel to |
~ the interface device. A routine to controlone ofthese _
devices — for example, a print routine — needs the ©
address of the device’s interface register. If the device
is relocated in the memory map, or if there is more
than one device of that type, then itis much simpler to
deal with this by changing one memory location that
contains the address of the device communication
register (a pointer to the device) rather than having to
find and change every occurrence of the device
address. The routine refers to the device indirectly,
using the pointer.
This example illustrates the general usage of
indirect addressing — when addresses that a program
refers to may be changed, it is more convenient to use
fixed-address pointers to refer to these locations. In -
this way, changes in the actual locations require only
changes in the pointer contents: the program refers to
the addresses indirectly.
Indirect Indexed Addressing
The argument [A,X] of the LDA.
instruction is in brackets,
meaning that the contents of X
(SC019 here) are to be added to
the contents of A (S23), givinga —
16-bit address (SC03C). This
byte and the next (SCO3D) are to
be treated as apointertothe —
effective load address (SF84B)
whose contents (S7E) are finally -
loaded into A. Because X is added
to A before the indirect access,
this is known as pre-indexed
indirection; the alternative, post-
indexing, requires that the indirect
address be calculated before the
indexing takes place —
The most common use of this technique is in a
structure known as a jump table, which is simply a
table of pointers. Any operating system contains a
large number of useful routines that carry out the
elemental functions of the machine — for example,
reading a character from the keyboard or displaying a
‘THE HOME COMPUTER ADVANCED COURSE 637
COURTESY OF AIR CALL
Vital though indirect addressing
is to computer operations, it is
difficult to find examples of the
technique in real life. A
reasonable analogy, however, is
a radio paging service. When
- someone wants to talk to a
subscriber, he doesn't call them
directly, because they could be
anywhere. Instead, he calls the
paging service, who then page
the subscriber. This is a simple,
flexible system in which the
paging service provides indirect
accessing (or addressing) of its
subscribers
character on the screen. Most machine code
programs will need to use these routines at some
time. In most cases, these routines will be accessed by
using a jump table, which means that routines
pointed to by the jump table vectors may be changed,
or relocated in memory, without changes being
needed in the programs that use them. In other
words, such routines are always accessed indirectly,
through the appropriate pointers in the jump table.
When a new version of an operating system is
designed, or an updated ROM produced, itis rare for
these primitive OS routines to remain in their original
positions; but if the jump table remains in position,
with its pointers altered so that they reflect the new
OS routine addresses, any software written for the
old operating system that uses the jump table will run
unchanged on the new system.
A common technique used in many operating
systems is to have one entry point and to make all
subroutine calls to this one address. One of the CPU
registers is used in addition to pass a function code
that is used to determine which subroutine will be
called. This function code is used as an index or offset
into the appropriate vector of the jump table, and
control is transferred through this pointer to the
desired routine.
_As an example, let us suppose that we have four
Kbytes of ROM, located at SF000, the first 256 bytes
of which ($F000 to SFOFF) contain a table of up to 128
addresses of subroutines stored in the ROM. The
entry routine (the address by which all the OS
routines are addressed) is located at $F100, and this
expects a function code in the range 0 to 127 to be
638 THE HOME COMPUTER ADVANCED COURSE
Indirect Access |
stored in accumulator B; this code is used by the entry
routine to pass control to the appropriate subroutines
and thence back to the calling program once
execution is complete. The calling routine for
function number 1 is:
put the function code in B
call the entry subroutine
_ The entry routine itself is:
Start address of the jump table
shift B one place to the left (equivalent to multiplying
the contents of B by two) since each entry in the table is
two bytes long. Thus the pointer appropriate to function
code 1 is stored at SFO02 and SF003, while the pointer
for code 2 is at SF004 and SF005, and so on
transfer control to the address found at the Bth position
in the table
Note that the transfer to the routine is handled by a
BRA (or JMP) rather than a BSR (or JSR); this is so that
the RTS at the end of the OS routine will return
control directly to the calling program instead of back
to this entry routine.
Our next example shows a further possible use of
indirect addressing in dealing with a memory
mapped display screen; on many micros the screen
memory occupies.a block of the main memory and
IAN McKINNELL
may be accessed directly if extra speed is required. ©
For simplicity, let us assume that the screen occupies
a block of memory from SE000 to SE3FF, representing
16 lines of 64 characters. The position of the cursor is
a 16-bit value in this range, and is located at $E400.
The first subroutine clears the screen by writing a
space character (ASCII code 32) at each character
position. The second subroutine will write the
eS aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaamaaaaaaaacamcascacmacmascacmmmcccmccccccccssslll
EE Eee : -
gc ’
character passed in A to the screen at the current
cursor position, unless that character is a carriage
return (ASCII 13), in which case it will clear the rest
of the line and position the cursor at the beginning of
the next line. The cursor is represented by the
underline character (‘“__’) in this example. :
CURSOR
CURCHR
~ EQU 32 ASCII code for space
EQU 13 ASCII code for carriage return
EQU $E000 Start of screen memory
EQU 1024 Size of.screen memory (16 lines x 64
characters = 1024)
EQU $E400 SE400 and SE401 together point to
the current address of the cursor in
screen memory area
ORG $1000
FCB 95 Underline character (ASCII 95)
-s “Subroutine to clear screen***
LOOP
LDA #SPACE Space character in A
LOX #HOME Point cursor to beginning of screen
STX CURSOR Store current cursor position at
CURSOR (i.e. SE400, SE401)
LOB #LENGTH = Size of screeninB
STA (CURSOR) Store a space in current cursor
3 position
INC CURSOR Increment cursor position
DECB Decrement amount of screen
memory remaining between cursor
position and end of screen memory
BGT LOOP1 Next space, until no more screen
-* memory remains -
STX CURSOR Cursor back to home position
LDA CURSOR ASCII code of cursor character in A
STA [CURSOR] Store cursor character in current
Cursor position
RIS =.
***Subroutine to display character in A, if displayable*** ,
CHKEOS
~ ***§Subroutine to scroll screen***
SCROLL
LOOP2
NOTP
CMPA SPACE Space is the first printable character —
in ASCII
BLT NOTP lf accumulator contains ASCII value
| less than 32, this is non- printable, SO
GOTONOTP ~ |
STA [CURSOR] Store in current cursor position
INC CURSOR Increment cursor position
LOX #HOME Check for end of screen
LEAY #LENGTH,X End of screen in Y
CMPY CURSOR If cursor position exceeds end of
~ §creen then...
BGT FINISH we have reached the end of the
screen, SO GOTO FINISH
LEAY64,X Y is one line length from X (end of
screen memory)
LOB #LENGTH Calculate amount to scroll
SUBB #64 Subtract 64 from length
LDA ,Y+ Move characters back one line (notice
gh auto-increment — see page 618)
STA ,X+
DECB
BGT LOOP2 Loop until scrolling complete
LOD CURSOR Cursor to start of last line
SUBD #64 :
STD CURSOR
BRA FINISH
**“Subroutine to check for carriage return **
. COMPA #CR Is this non- cen character a
carriage return?
_ BNE FINISH Ignore if not
_ FINISH
LDD CURSOR ‘You can work out how this gives the -
ANDB #%11100000 start of the next line Ueiee binary
AND-mask)
ADDD #64
STD CURSOR
BRA CHKEOS — Check if end of screen
LDA CURSOR Cursor character in A
STA[CURSOR] = Store in current cursor position
_ THE HOME COMPUTER ADVANCED COURSE 639
ompute
its copyright jea ous! y and these | rave all
& o differed, at least cosmetically, from the
original. Atarisolt has now agen ‘official’
pot—tl — ter of tl exide of ts At: |
ND whereas the rahe are twice as mi as
ie alae
the original arcade maze game, and set ie as that on nthe Moai version :
|
e formula that has since been follow cf by home an gives fuller instructions, 4
computer s« mes like Atic Atac and Jet Set Willy. In
uch ga entral character must travel through }
+ a network 0 spain or rooms, all the while picking ersions. There is little. ‘. One |
rie * -_ up treasure and avoiding the various hazards along ers could have done about
the way.
nder certain conditions, it is epost for
the playe atta
— in Sab
orchids me
the jungl
games, 1
similar ite 7
In Pacman, the
centre of a maze, é
: e |Or iginal, the ering be
playing t e game Bae like
im. The V version’ S apres |
Kes the pier invisible to the anes in
is idea was borrowed from adventure
| ich the posse IC SV
e player an advantage.
tle character is ee at the
en Pacman first made an appearance in 1980,
quickly became a aso but today a
al software ————
pe games, Lees the
ination to trap the Pacman in the various ae ne
| company has ¢
STiClal Versio machines S
_ scoring extra points, at e Te
es and add to ae, score if Sick: :
parison different versions of the same
doce oon of the ms original.
2 Este the most of that micro’s aeits
__ particularly true for games designed s
Atari machines, yaa re an enviable re
eatures ¢
arge maze with excellent sound i graphics
smooth sprite movement anc various skill levels
¢ for the fact that the game is not played
a faithful
% wah
rene
>
LIZ DIXON
640 THE HOME COMPUTER ADVANCED COURSE ee a3 € c
-—
SACHA CalOuD
Symbolic
DESTINATION
bee 8
SOURCE
HL points to source
DE points to destination
BC is byte counter
DATABASE
Here, courtesy of Zilog Inc., we produce another part of the Z80 programmers’ reference card.
Block Search Group
SEARCH
LOCATION HL points to location in mamory
to be compared with
accumulator contents
BC is byte counter
| Ipod eVouele(-¥ 1s) (ole a Mb det stss(-1g9 onelelrel-lotyel ol Give) hy ors
(@lerorele) =
H
No. of
No.of M No.of 7
Comments
Mnemonic Operation Ss H PIV N C 76 543 210 ex Bytes Cycles States
oo Do —rr—“‘—C—C—C—SC—s—<—MsS<S<—M~;Z3=~C~CWeadéseézststtiéteitistOCN 4
Px Ar Al AD A — rr—“—~—s—s—sCOSNC*C=C*s =. : .
_ ee — —rr——ONNSCN (UOrCiCiaC ia‘ O aR... CC 4
tie DE :
bo HL Dank Exch age
Ee H - SP 41) + 6 Xe ke ks 3 co ES : & :
L- GF
Ex SPi x hk S 6 & 6 6 Bh Fee ce = . S
oe oe
EX Sey ig Gh ‘6 ke eG 2 PO . e —
iY : ee aes ES
OD
LO} fb Ss 6 Ks eee aes . 4 ue
DE OE at 1
Bo - BA -
LOIR iL * © § © § hhmhUmUcmCmUCmD 1 EO é s ce
D 10 — .. : -
OG
a
a:
B :
ee
LOD ® * x o : * ec 2 4 a.
As
LDOR — rrr—e—“‘i‘C ‘CCC . ‘ - . _.
e 4 Ce : oe :
cP A - HL | ee . —— 4 ie
ee ee a
BO -
oF 5 a i... . fo 5 e :
- a : 4 16 y
ep A. ‘ fx : ee : . . 3
Be oe
BU - - _ _
-
CPDR A i. =. - oe 2 a c
HL oo oe 4 u
Bo
Re
A
ae
NOTES py fag § Ci the resull ci BU | = 0 olhenwise Fv =
—.
ce = Hag reset | = KX = (ag § UpRDOWS
Fiag Nolavor
flag nol atfecied o
} = Jac § alleciec according {c [he esu:
Pag sel
Hl